package com.carrot.gateway.util;

import cn.hutool.core.util.StrUtil;
import com.carrot.auth.constants.JwtConstants;
import org.springframework.http.HttpHeaders;

/**
 * 权限工具类
 */
public class AuthUtil {

    /**
     * 获取请求头中的token 并去掉Bearer前缀
     * @param headers
     * @param key
     * @return
     */
    public static String handleToken(HttpHeaders headers, String key){
        String sourceToken = headers.getFirst(key);
        return StrUtil
                .emptyToDefault(sourceToken,"")
                .replace(JwtConstants.TOKEN_HEAD, "");
    }


}
